package com.buric.common.exception;

import com.buric.common.data.R;
import com.buric.common.emun.ResultEnums;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: zhou.wei
 * @description 异常处理
 * @date: 2024/5/20 10:30
 */

@ControllerAdvice
@Slf4j
public class ExceptionAdvice {


    @ExceptionHandler(RuntimeException.class)
    public R<String> runtimeExceptionHandler(HttpServletRequest request,RuntimeException e) {
        log.error("【系统繁忙】:{}", e.getMessage());
        return R.fail(ResultEnums.FAIL.getCode(),null,e.getMessage());
    }

    @ExceptionHandler(ServiceException.class)
    public R<String> serviceExceptionHandler(HttpServletRequest request,ServiceException e) {
        log.error("【业务异常】:{}", e.getMessage());
        return R.fail(ResultEnums.FAIL.getCode(),null,e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public R<String> allExceptionHandler(HttpServletRequest request,Exception e) {
        log.error("【系统繁忙】:{}", e.getMessage());
        return R.fail(ResultEnums.FAIL.getCode(),null,e.getMessage());
    }


}
